const { toTryCatch } = require("../../utils")
const fs = require('fs-extra');
module.exports = {
    signInDao: async (req, data) => {
        // return await req.Model.create({
        //     username: '123123',
        //     password: '123123',
        //     email: '568055454@qq.com',
        //     role: 'admin',
        //     camera: [],
        //     file: []
        // })

        // const File = require("../../models/File");
        // await File.create({
        //     uuid: require('uuid').v4(),
        //     name:'hVideo',
        //     path:'C:\\Users\\胡永乐\\hVideo',
        //     type:'root',
        // })
        // const fileIO = require('../../utils/fileIO');
        // console.log(await fileIO.getDirectoryInfo('C:\\Users\\胡永乐\\hVideo\\test.mp4'));
        const err = {}
        const user = await toTryCatch(() => req.Model.findOne({ username: data.username }).populate('camera').exec())
        if (!user) {
            return { type: 'error', message: '用户不存在！' }
        }
        const isPasswordValid = await toTryCatch(() => req.Model.findOne(data).exec())
        if (!isPasswordValid) {
            return { type: 'error', message: '密码错误！' }
        }
        return user
    }
}
